package com.tps.endpoint;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.endpoint.FrameworkEndpoint;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author charlee.wu
 * @date 2018/5/8 15:58
 **/
@FrameworkEndpoint
public class RevokeTokenEndpoint {

    private final ConsumerTokenServices consumerTokenServices;

    @Autowired
    public RevokeTokenEndpoint(ConsumerTokenServices consumerTokenServices) {
        this.consumerTokenServices = consumerTokenServices;
    }

    @DeleteMapping("/oauth/token")
    @ResponseBody
    public String revokeToken(String access_token) {
        if (consumerTokenServices.revokeToken(access_token)) {
            return "revoke token success";
        } else {
            return "revoke token failed";
        }
    }
}
